import csv
import os.path
import random
import pandas as pd

def save_to_csv(rowData):
    with open('detailList.csv', 'a', newline='', encoding='utf-8') as wf:
        writer = csv.writer(wf)
        writer.writerow(rowData)

def init():
    if not os.path.exists('./detailList.csv'):
        with open('detailList.csv', 'w', newline='', encoding='utf-8') as file_obj:
            writer = csv.writer(file_obj)
            writer.writerow(['detailLink', 'tasterate', 'envsrate', 'serverate'])

if __name__ == '__main__':
    # init()
    df = pd.read_csv('dataList.csv')
    column_10 = df.iloc[:, 9].tolist()

    for detail in column_10:
        # 生成随机的tasterate, envsrate, serverate，这些值都小于5.0
        tasterate = round(random.uniform(2.0, 5.0), 1)
        envsrate = round(random.uniform(2.0, 5.0), 1)
        serverate = round(random.uniform(2.0, 5.0), 1)

        # 保存到detailList.csv
        save_to_csv([detail, tasterate, envsrate, serverate])
        print(f"Saved: {detail}, {tasterate}, {envsrate}, {serverate}")

